package chapter1.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import chapter1.models.Customer;
import chapter1.service.CustomerService;
@WebServlet("/customer_show")
public class CustomerListServlet extends HttpServlet {
	
	private static final Logger LOGGER=LoggerFactory.getLogger(CustomerListServlet.class);
	CustomerService cs=new CustomerService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Customer> customers=  cs.getCustomers(null);
		if(!customers.isEmpty()){
			LOGGER.error("获取成功");
			LOGGER.info("获取用户列表成功");
		}
		req.setAttribute("customers", customers);
		req.getRequestDispatcher("/WEB-INF/jsp/customerShow.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}
